package com.hutao.medical.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.hutao.medical.common.config.ConfigProperties;
import com.hutao.medical.common.util.HttpClientUtil;
import com.hutao.medical.common.util.JsonUtils;
import com.hutao.medical.common.util.Result;
import com.hutao.medical.constant.Constant;

@Service
public class BasicDataService {
	
//	@Value("${basic.data.url}")
//	private String basicDataUrl;
	@Autowired
	private ConfigProperties configProperties;

	public Map<String, List<Map<String, Object>>> getBaseInfoMap() {
		Map<String,List<Map<String,Object>>> baseInfoMap=new HashMap<>();
		if(MapUtils.isNotEmpty(Constant.baseInfoMap)){
			baseInfoMap=Constant.baseInfoMap;
		}else{
			String userJson = HttpClientUtil.doPost(configProperties.getMedicalManage().getBasicDataPath());
			if(StringUtils.isNoneEmpty(userJson)){
				Result result=JsonUtils.jsonToPojo(userJson, Result.class);
				if(result.isSuccess()){
					baseInfoMap=(Map<String, List<Map<String, Object>>>) result.getData();
					Constant.baseInfoMap=baseInfoMap;
				}
			}
		}
		return baseInfoMap;
	}
}
